var _serviceURL = '/69mark/web';// 必须设置

$(function() {
	
	doPage(1);
	
});

function doPage(page){
	var name = $("#serchName").val();
	var parent = $("#parent").val();
	
	$.ajax({
   		type : "POST",
   		url : _serviceURL+"/toListAllSecretaryTwo.do",
   		cache : false,
   		data : "pageNo="+page+"&pageSize=10&name="+name+"&parent="+parent,
   		dataType : 'json',
   		success : function(data) {
   			var result = "";
   			for(var i=0;i<data.menuList.length;i++){
   				result += "<tr>";
   				result += "<td>"+data.menuList[i].name+"</td>";
   				
   				result += "<td>￥"+data.menuList[i].price+"</td>";
   				result += "<td>";
   				result += "<a href=\"javascript:void(0);\" title=\"修改\" class=\"xiugai\" onclick=\"sgthShow('"+data.menuList[i].id+"','"+data.menuList[i].name+"','"+data.menuList[i].price+"')\">修改</a>";
   				result += "<a href=\"\" onclick=\"delfuncitem('"+data.menuList[i].id+"');return false;\" style=\"margin-left: 10px;\" title=\"删除\">删除</a>";
   				result += "</td>";
   				result += "</tr>";
   			}
   			
   			$("#heightList").html(result);
   			$("#page_user").html(data.navi);
   			
   			$("#serchName").val("");
   		}
	})
}

//
function sgthShow(id,name,price){
	$(".sgtk3").show();
	$("#id").val(id);
	$("#uName").val(name);
	$("#price").val(price);
}

//身高搜索
function serchName(){
	doPage(1);
}

//删除
function delfuncitem(thisid){
    layer.confirm('确定删除？',{btn:['确定','取消']},function(){
            $.ajax({
                type:'POST',
                url:_serviceURL+'/toDeleteSecretaryId.do',
                data:'id='+thisid,
                dataType : 'json',
                success:function(data){
                    if(data==1){
                        layer.msg('删除成功',{
                            time: 2000,
                        });
                        doPage(1);
                    }else{
                        layer.msg('删除失败',{
                            time: 2000,
                        });
                    }
                }
            });
        }
    );
}

function saveSecretary(){
	var name = $("#name").val();
	if (name == '') {
		return false;
	}
	$.ajax({
        type:'POST',
        url:_serviceURL+'/toSaveSecretary.do',
        data:'name='+name,
        dataType : 'json',
        success:function(data){
            if(data==1){
            	$("#name").val("");
            	$(".sgtk").css("display", "none");
				doPage(1);
            }
        }
    });
}

function updateSecretary(){
	var id = $("#id").val();
	var name = $("#uName").val();
	var price = $("#price").val();
	var parent = $("#parent").val();
	
	if (name == '' || price == '') {
		return false;
	}
	
	$.ajax({
        type:'POST',
        url:_serviceURL+'/toUpdateSecretaryId.do',
        data:'id='+id+'&name='+name+"&price="+price,
        dataType : 'json',
        success:function(data){
            if(data==1){
            	$("#id").val("");
            	$("#uName").val("");
            	$(".sgtk3").css("display", "none");
				window.location.href = _serviceURL+"/toSecretaryIndex2?parent="+parent;
            }
        }
    });
}

//添加二级分类
function saveSecretary2(){
	var name = $("#name2").val();
	var parent = $("select option:selected").attr("select_value");
	var price = $("#price").val();
	
	if (name == '' || parent == '' || parent == undefined || price == '') {
		return false;
	}
	
	$.ajax({
        type:'POST',
        url:_serviceURL+'/toSaveSecretary2.do',
        data:'name='+name+"&parent="+parent+"&price="+price,
        dataType : 'json',
        success:function(data){
            if(data==1){
            	$("#name2").val("");
            	$("#price").val("");
            	$(".sgtk2").css("display", "none");
				doPage(1);
            }
        }
    });
}


